
//
//  ByViewRegistrationHeader.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/9.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByViewRegistrationHeader.h"

@implementation ByViewRegistrationHeader
{
    UIImageView     *_selectImg;
    UILabel         *_hospitalLabel;
    UIButton        *_switchButton;
    UIView          *_line;
}
- (instancetype)init{
    if (self = [super init]) {
        [self createViews];
    }
    return self;
}

#pragma mark - create views
- (void)createViews{
    _selectImg = [[UIImageView alloc] init];
    [self addSubview:_selectImg];
    [_selectImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    _selectImg.image = [UIImage imageNamed:@"Index_dingwei_gray"];
    
    _switchButton = [[UIButton alloc] init];
    [self addSubview:_switchButton];
    CGFloat width = [@"切换分院" getSizeOfString:14].width + 40;
    [_switchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-10));
        make.top.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(width, 30));
    }];
    [_switchButton setImage:[UIImage imageNamed:@"Index_switch"] forState:UIControlStateNormal];
    [_switchButton setTitle:@"切换分院" forState:UIControlStateNormal];
    [_switchButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _switchButton.backgroundColor = BY_THEME_COLOR;
    _switchButton.layer.cornerRadius = 4.0;
    _switchButton.titleLabel.font = FONT(14);
    [_switchButton setImageEdgeInsets:UIEdgeInsetsMake(0, 10, 0, width - 30)];
    [_switchButton addTarget:self action:@selector(switchHospital) forControlEvents:UIControlEventTouchUpInside];
    
    _hospitalLabel = [[UILabel alloc] init];
    [self addSubview:_hospitalLabel];
    [_hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_selectImg.mas_right).offset(5);
        make.top.equalTo(@(10));
        make.right.equalTo(_switchButton.mas_left);
        make.bottom.equalTo(@(-10));
    }];
    _hospitalLabel.font = FONT(14);
    _hospitalLabel.textColor = [UIColor lightGrayColor];
    
    _line = [[UIView alloc] init];
    [self addSubview:_line];
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.bottom.equalTo(@(0));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 1));
    }];
    _line.backgroundColor = [UIColor colorWithWhite:0.90 alpha:1];
}

- (void)setModel:(ByModelIndexBranch *)model{
    _model = model;
    _hospitalLabel.text = _model.name;
}

#pragma mark - 切换分院
- (void)switchHospital{
    if (self.switchBlock) {
        self.switchBlock(_model);
    }
}

@end
